﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Htxw.AMFRemoting;
using System.Net;
using FluorineFx;

namespace DotNetRemotingTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RemoteObject rmt = new RemoteObject();
            try
            {
                rmt.Connect(m_ctrlIP.Text, int.Parse(m_ctrlPort.Text));

                DateTime tick = DateTime.Now;
                ArrayList cars = new ArrayList();

                for (int i = 0; i < 1000; i++)
                {

                    DateTime _now = DateTime.Now;
                    string fun_name = "Test1";
                    object[] call_params = new object[] { "hello", 2, 3 };
                    object ret = rmt.CallDirect("CDataInterface", fun_name, call_params);

                    this.label1.Text = i.ToString() + "" + ret.ToString();
                    Application.DoEvents();
                }
                TimeSpan span = (DateTime.Now - tick);
                this.label1.Text = "used time :" + ((float)span.TotalMilliseconds)/1000 + "(S)";

                rmt.CloseConnect();
            }
            catch (Exception ee)
            {
                this.label1.Text = ee.Message;
                if (rmt.IsConnected)
                    rmt.CloseConnect();
            }
        }

        ArrayList objs = new ArrayList();
        private void OnGetGPSData(object sender, EventArgs e)
        {
            RemoteObject rmt = new RemoteObject();
            //rmt.AutoCloseConnect = false;
            rmt.Connect(m_ctrlIP.Text, int.Parse(m_ctrlPort.Text));
            try
            {
                DateTime tick = DateTime.Now;

                for (int i = 0; i < 1000; i++)
                {
//                    rmt = new RemoteObject();
                    objs.Add(rmt);

                    DateTime _now = DateTime.Now;
                    DateTime zDate = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc);
                    long tt = zDate.Ticks + 1283734565000 * 1000 * 10;
                    DateTime pdate = new DateTime(tt, DateTimeKind.Utc);

                    string fun_name = "GetGPSData";
                    object[] call_params = new object[] { 
                                        88888888,//Convert.ToUInt32(textBox1.Text), 
                                        pdate,//new DateTime(2010,9,1,18,17,26,DateTimeKind.Utc),
                                        pdate,//new DateTime(2010,9,20,18,17,26,DateTimeKind.Utc)
                                       // DateTime.Now                                        //new DateTime(2010,11,5,19,7,1,DateTimeKind.Utc),
                    };
                    object ret = rmt.CallDirect("DSHandle", fun_name, call_params);
                    //rmt.CloseConnect();

                    this.label1.Text = i.ToString() + "" + ret.ToString();
                    Application.DoEvents();
                }
                TimeSpan span = (DateTime.Now - tick);
                this.label1.Text = "used time :" + ((float)span.TotalMilliseconds) / 1000 + "(S)";

                //rmt.CloseConnect();
            }
            catch (Exception ee)
            {
                this.label1.Text = ee.Message;
                if (rmt.IsConnected)
                    rmt.CloseConnect();
            }
        }
    }
}
